<%--
功能: 显示操作者名称，可能是管理员，也有可能是顾客
--%>
<%@ tag import="com.probiz.estore.common.model.customer.Customer"%>
<%@ tag import="com.probiz.estore.common.model.system.AppAdmin"%>
<%@ tag import="com.probiz.estore.Constants" %>
<%@ tag import="org.apache.commons.lang.StringUtils"%>
<%@ tag import="org.springframework.context.ApplicationContext" %>
<%@ tag import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ tag import="com.probiz.estore.system.service.AppAdminManager" %>
<%@ tag import="com.probiz.estore.customer.service.CustomerManager" %>
<%@ tag import="com.probiz.estore.core.view.MessageContext" %>
<%@ tag import="org.springframework.context.support.ReloadableResourceBundleMessageSource"%>
<%@ tag import="java.util.Locale"%>
<%@ attribute name="userId" required="true" rtexprvalue="true" type="java.lang.String" description="appUser ID"%>
<%@ attribute name="defaultValue" required="false" rtexprvalue="true" type="java.lang.String" description="找不到实体或者id是匿名时候的显示值"%>

<%
if(defaultValue == null)defaultValue="";
String userName ="";
if (StringUtils.isNotBlank(userId)){
	//输出用户名链接
	ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(application);
	AppAdminManager appAdminManager = (AppAdminManager)ctx.getBean("appAdminManager");
	CustomerManager customerManager = (CustomerManager)ctx.getBean("customerManager");
	ReloadableResourceBundleMessageSource messageSource = (ReloadableResourceBundleMessageSource)ctx.getBean("messageSource");
	Locale locale = null;
	locale = request.getLocale();
	//MessageContext messageContext = (MessageContext)ctx.getBean("messageContext");
	String ctxPath = (String)application.getAttribute("ctxPath");

	AppAdmin appAdmin = null;
	Customer customer = null;
	try {
		appAdmin = appAdminManager.loadById(Integer.valueOf(userId));
		userName=appAdmin.getFullName()+messageSource.getMessage("salesOrder.operator.admin",null,locale);
	} catch (java.lang.Throwable e) {
		try{
			customer = customerManager.loadById(Integer.valueOf(userId));
			userName=customer.getFullName()+messageSource.getMessage("salesOrder.operator.customer",null,locale);
			if(customer.getAppuserId().equals(-2)){
			if(defaultValue.equals("")){
				defaultValue = messageSource.getMessage("customer.regist.byCustomer",null,locale);
			}
				userName = defaultValue;
			}
		}catch(java.lang.Throwable e2){
			System.err.println("error looking up user with id: "+userId);
			//下面此句用于避免异常：could not initialize proxy。因为一定可以获取
			appAdminManager.getById(1);
			if(defaultValue.equals("")){
				defaultValue = messageSource.getMessage("customer.regist.byCustomer",null,locale);
			}
			userName = defaultValue;
		}
	}
}
out.write(userName);
%>
